#!/bin/bash
#安装libks
if [ ! -e "libks" ]; then
  git clone https://github.com/signalwire/libks.git
fi
cd libks
cmake . 
make
sudo make install
cd ..
#安装sofia-sip
if [ ! -e "sofia-sip" ]; then
  git clone https://github.com/freeswitch/sofia-sip.git
fi
cd sofia-sip
./bootstrap.sh -j
./configure
make
make install
cd ..
#安装spandsp
if [ ! -e "spandsp" ]; then
  git clone https://github.com/freeswitch/spandsp.git
fi
cd spandsp
#git checkout -b finecode20230705 0d2e6ac65e0e8f53d652665a743015a88bf048d4
./bootstrap.sh -j
./configure
make
make install
#安装Freeswitch
apt-get update && apt-get install -yq gnupg2 wget lsb-release
wget --http-user=signalwire --http-password=pat_KJym6TEtUK6PmADrgBV9A1zp -O /usr/share/keyrings/signalwire-freeswitch-repo.gpg https://freeswitch.signalwire.com/repo/deb/debian-release/signalwire-freeswitch-repo.gpg

echo "machine freeswitch.signalwire.com login signalwire password pat_KJym6TEtUK6PmADrgBV9A1zp" > /etc/apt/auth.conf
chmod 600 /etc/apt/auth.conf
echo "deb [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" > /etc/apt/sources.list.d/freeswitch.list
echo "deb-src [signed-by=/usr/share/keyrings/signalwire-freeswitch-repo.gpg] https://freeswitch.signalwire.com/repo/deb/debian-release/ `lsb_release -sc` main" >> /etc/apt/sources.list.d/freeswitch.list

apt-get update
apt-get build-dep freeswitch
cd ..
if [ ! -e "freeswitch" ]; then
  cp -r freeswitch /usr/src/
fi
cd /usr/src/
if [ ! -e "freeswitch" ]; then
  git clone https://github.com/signalwire/freeswitch.git -bv1.10 freeswitch
fi
cd freeswitch
git config pull.rebase true
./bootstrap.sh -j
./configure
make
make install
make cd-sounds-install cd-moh-install
cd /usr/local
chown -R www:www freeswitch/